package com.lyncs.ods.resp;

import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.lyncs.ods.modules.txn.model.OrderInfo;
import com.lyncs.ods.modules.txn.model.TagInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @author alex
 * @date 2022/2/8 23:19
 * @description
 */
@Data
@Accessors(chain = true)
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class OrderDetailInfoResp {

    @ApiModelProperty(value = "订单ID")
    private Long orderId;

    @ApiModelProperty(value = "交付次数")
    private Integer deliverCount;

    @ApiModelProperty(value = "总金额")
    private String totalAmount;

    @ApiModelProperty(value = "状态")
    private Integer status;

    @ApiModelProperty(value = "货币")
    private String currency;

    @ApiModelProperty(value = "是否置顶。true;false")
    private Boolean top;

    @ApiModelProperty(value = "订单开始时间")
    private LocalDate startDate;

    @ApiModelProperty(value = "创建时间")
    private LocalDateTime createTime;

    @ApiModelProperty(value = "预计交付时间")
    private LocalDate estimatedDeliveryTime;

    @ApiModelProperty(value = "订单名称")
    private String orderName;

    @ApiModelProperty(value = "卖方公司信息")
    private CompanyShortInfoResp sellerCompanyInfo;

    @ApiModelProperty(value = "买方公司信息")
    private CompanyShortInfoResp buyerCompanyInfo;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "创建者用户名称")
    private String creatorName;

    @ApiModelProperty(value = "更新时间")
    private LocalDateTime updateTime;

    @ApiModelProperty(value = "sku部分交付类别数")
    private Integer partialCount;

    @ApiModelProperty(value = "sku全部交付类别数")
    private Integer deliveredCount;

    @ApiModelProperty(value = "sku未交付类别数")
    private Integer undeliveredCount;

    @ApiModelProperty(value = "创建者用户所属公司ID")
    private Long creatorCompanyId;

    @ApiModelProperty("目的地港/机场")
    private String destinationPort;

    @ApiModelProperty("包装")
    private String packing;

    @ApiModelProperty("唛头")
    private String shippingMarks;

    @ApiModelProperty("贸易规则")
    private String tradingTerms;

    @ApiModelProperty("支付方式")
    private String paymentTerms;

    @ApiModelProperty("运输方式")
    private String shipment;

    @ApiModelProperty("装运港/机场")
    private String loadingPort;

    @ApiModelProperty("转运港/机场")
    private String transshipmentPort;

    @ApiModelProperty("自定义字段信息")
    private String customFields;

    @ApiModelProperty("附件")
    private String attachment;

    @ApiModelProperty(value = "sku 详情")
    private List<OrderSkuInfo> skuInfoList;

    @Data
    @Accessors(chain = true)
    @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
    public static class OrderSkuInfo {

        @ApiModelProperty(value = "skuID")
        private Long skuId;

        @ApiModelProperty(value = "内部货号")
        private String innerCode;

        @ApiModelProperty(value = "sku名称")
        private String name;

        @ApiModelProperty(value = "本次交易本SKU需要交付数量")
        private BigDecimal totalCount;

        @ApiModelProperty(value = "已交付商品数")
        private BigDecimal deliveredCount;

        @ApiModelProperty(value = "总价")
        private String totalAmount;

        @ApiModelProperty(value = "单价")
        private String amount;

        @ApiModelProperty(value = "单位")
        private String unit;

        @ApiModelProperty(value = "sku图片")
        private String imgUrl;

        @ApiModelProperty(value = "备注")
        private String remark;

        @ApiModelProperty("标签信息")
        private List<TagInfo> tagInfos;

        @ApiModelProperty(value = "sku属性")
        private Map<String, String> skuAttrs;
    }

    public OrderDetailInfoResp(OrderInfo orderInfo) {
        this.setOrderId(orderInfo.getId())
                .setStatus(orderInfo.getStatus())
                .setStartDate(orderInfo.getStartDate())
                .setCreateTime(orderInfo.getCreateTime())
                .setEstimatedDeliveryTime(orderInfo.getEstimatedDeliveryTime() == null ? null : orderInfo.getEstimatedDeliveryTime().toLocalDate())
                .setOrderName(orderInfo.getOrderName())
                .setRemark(orderInfo.getRemark())
                .setUpdateTime(orderInfo.getUpdateTime())
                .setCurrency(orderInfo.getCurrency())
                .setCreatorCompanyId(orderInfo.getCreatorCompanyId())
                .setDestinationPort(orderInfo.getDestinationPort())
                .setPacking(orderInfo.getPacking())
                .setShippingMarks(orderInfo.getShippingMarks())
                .setTradingTerms(orderInfo.getTradingTerms())
                .setPaymentTerms(orderInfo.getPaymentTerms())
                .setShipment(orderInfo.getShipment())
                .setLoadingPort(orderInfo.getLoadingPort())
                .setTransshipmentPort(orderInfo.getTransshipmentPort())
                .setAttachment(orderInfo.getAttachment())
                .setCustomFields(orderInfo.getCustomFields());
    }
}
